package com.miyake.dsp.circuit.ui;

import com.miyake.dsp.circuit.RcSetting;
import com.miyake.dsp.ui.DspTextField;
import com.miyake.dsp.ui.DspWidget;

public class RcSettingUI extends DspWidget {

	/**
	 * 
	 */
	private static final long serialVersionUID = 7041174564602345134L;
	private RcSetting setting;

	public RcSettingUI(RcSetting setting) {
		this.setting = setting;
		createCapacitance();
		createResistance();
	}
	
	private void createCapacitance() {
		DspTextField text = new DspTextField("Capacitance");
		text.setValue(String.valueOf(setting.getCapacitance()));
		this.add(text);
		
		text.addHandler(new DspWidgetHandler() {
			@Override
			public void onChange(String value) {
				setting.setCapacitance(Double.valueOf(value));
				fireChange(value);
			}
		});	
	}
	
	private void createResistance() {
		DspTextField text = new DspTextField("Resistance");
		text.setValue(String.valueOf(setting.getResistance()));
		this.add(text);
		
		text.addHandler(new DspWidgetHandler() {
			@Override
			public void onChange(String value) {
				setting.setResistance(Double.valueOf(value));
				fireChange(value);
			}
		});	
	}
}
